package com.easychat.entity.enums;

import com.easychat.utils.StringTools;

/**
 * @Author Dongdong
 * @注释
 */

public enum UserContactTypeEnum {
    USER(0, "U", "好友"),
    GROUP(1, "G", "群");
    //类型
    private Integer type;
    //前缀
    private String prefix;
    //描述
    private String desc;

    //通过查看是否包含prefix得到枚举
    public static UserContactTypeEnum getByPrefix(String prefix){
        try{
            if (StringTools.isEmpty(prefix) || prefix.trim().length()==0){
                return null;
            }
            prefix = prefix.substring(0,1);
            for (UserContactTypeEnum typeEnum : UserContactTypeEnum.values()){
                if (typeEnum.getPrefix().equals(prefix)){
                    return typeEnum;
                }
            }
            return null;
        }catch (Exception e){
            return null;
        }
    }


    UserContactTypeEnum(int type, String prefix, String desc) {
        this.type = type;
        this.prefix = prefix;
        this.desc = desc;
    }

    public static UserContactTypeEnum getByName(String contactType) {
        for (UserContactTypeEnum type : values()) {
            if (type.name().equals(contactType)) {
                return type;
            }
        }
        return null;
    }

    public Integer getType() {
        return type;
    }

    public String getPrefix() {
        return prefix;
    }

    public String getDesc() {
        return desc;
    }
}
